private void ScrambleNonceUsingDefaultMethod(byte[] nonce) { LogicRandom scrambler = new LogicRandom(this.m_scramblerSeed); for (int i = 0; i < nonce.Length; i++) { nonce[i] ^= (byte)scrambler.Rand(256); } }
public static void Init() { UserManager.m_presetLevels = new LogicArrayList <string>(); UserManager.m_presetRandom = new LogicRandom(TimeUtil.GetTimestamp()); LogicArrayList <string> presetLevelFiles = EnvironmentSettings.Settings.Admin.PresetLevelFiles; for (int i = 0; i < presetLevelFiles.Size(); i++) { string json = ServerHttpClient.DownloadString("data/" + presetLevelFiles[i]); if (json != null) { UserManager.m_presetLevels.Add(json); } } }
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); } } }
/// <summary> /// Initializes the <see cref="Loader"/> class. /// </summary> internal static void Init() { if (Loader.Initialized) { return; } Loader.Random = new LogicRandom(); LogicCommandManager.Init(); MessageManager.Init(); Fingerprint.Init(); CSV.Init(); Globals.Init(); if (Settings.Database == DBMS.Mongo) { Mongo.Init(); } Connections.Init(); Avatars.Init(); Alliances.Init(); Battles.Init(); ServerConnection.Init(); APIHandler.Init(); ServerTimers.Init(); Loader.Initialized = true; EventsHandler.Init(); Tests.Init(); }
public void SpawnSummon(int x, int y) { LogicSpellData data = this.GetSpellData(); LogicCharacterData summonData = data.GetSummonTroop(); LogicVector2 position = new LogicVector2(); int summonCount = data.GetUnitsToSpawn(this.m_upgradeLevel); int spawnDuration = data.GetSpawnDuration(this.m_upgradeLevel); int totalSpawnDuration = -(spawnDuration * data.GetSpawnFirstGroupSize()); for (int i = 0, k = 0, angle = y + 7 * x; i < summonCount; i++, k += 7, angle += 150, totalSpawnDuration += spawnDuration) { if (!summonData.IsFlying()) { if (!this.m_level.GetTileMap().GetNearestPassablePosition(this.GetX(), this.GetY(), position, 1536)) { return; } } else { position.m_x = x + LogicMath.GetRotatedX(summonData.GetSecondarySpawnOffset(), 0, angle); position.m_y = y + LogicMath.GetRotatedY(summonData.GetSecondarySpawnOffset(), 0, angle); } LogicCharacter summon = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(summonData, this.m_level, this.m_villageType); summon.GetHitpointComponent().SetTeam(0); summon.SetInitialPosition(position.m_x, position.m_y); LogicRandom random = new LogicRandom(k + this.m_globalId); int rnd = ((random.Rand(150) << 9) + 38400) / 100; position.Set(LogicMath.Cos(angle, rnd), LogicMath.Sin(angle, rnd)); int pushBackSpeed = summonData.GetPushbackSpeed() > 0 ? summonData.GetPushbackSpeed() : 1; int pushBackTime = 2 * rnd / (3 * pushBackSpeed); int spawnDelay = pushBackTime + totalSpawnDuration / summonCount; if (data.GetSpawnFirstGroupSize() > 0) { spawnDelay = LogicMath.Max(200, spawnDelay); } summon.SetSpawnTime(spawnDelay); summon.GetMovementComponent().GetMovementSystem().PushTrap(position, pushBackTime, 0, false, false); if (summon.GetCharacterData().IsJumper()) { summon.GetMovementComponent().EnableJump(3600000); summon.GetCombatComponent().RefreshTarget(true); } LogicCombatComponent combatComponent = summon.GetCombatComponent(); if (combatComponent != null) { combatComponent.SetSkeletonSpell(); } this.GetGameObjectManager().AddGameObject(summon, -1); } }
/// <summary> /// Initializes this instance. /// </summary> internal static void Initialize() { AccountManager._accountCounters = new int[DatabaseManager.GetDatabaseCount(0)]; AccountManager._random = new LogicRandom(LogicTimeUtil.GetTimestamp()); AccountManager._accounts = new Dictionary <long, Account>(); }
public void CheckSpawning(LogicCharacterData spawnCharacterData, int spawnCount, int spawnUpgradeLevel, int invulnerabilityTime) { LogicCharacterData data = this.GetCharacterData(); if (spawnCharacterData == null) { spawnCharacterData = data.GetSecondaryTroop(); if (spawnCharacterData == null) { spawnCharacterData = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop(); if (spawnCharacterData == null) { return; } } } if (spawnCharacterData.IsSecondaryTroop() || this.IsHero()) { int totalSpawnCount = spawnCount; int upgLevel = this.m_upgradeLevel; if (upgLevel >= spawnCharacterData.GetUpgradeLevelCount()) { upgLevel = spawnCharacterData.GetUpgradeLevelCount() - 1; } if (this.IsHero()) { if (this.m_summonSpawnCount >= spawnCount) { return; } upgLevel = spawnUpgradeLevel; totalSpawnCount = LogicMath.Max(0, LogicMath.Min(3, spawnCount - this.m_summonSpawnCount)); } else { if (data.GetSecondaryTroopCount(this.m_upgradeLevel) != 0) { totalSpawnCount = data.GetSecondaryTroopCount(this.m_upgradeLevel); } else if (spawnCount == 0) { totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroopCount(); if (this.m_summonTroops.Size() + totalSpawnCount > data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit()) { totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit() - this.m_summonTroops.Size(); } } } if (totalSpawnCount > 0) { LogicVector2 position = new LogicVector2(); LogicRandom random = new LogicRandom(this.m_globalId); int team = this.GetHitpointComponent().GetTeam(); bool randomizeSecSpawnDist = this.GetCharacterData().GetRandomizeSecSpawnDist(); for (int i = 0, j = 0, k = 0; i < totalSpawnCount; i++, j += 360, k += 100) { int seed = j / totalSpawnCount; if (this.IsHero()) { seed = 360 * (i + this.m_summonSpawnCount) / LogicMath.Max(1, LogicMath.Min(6, spawnCount)); } int rnd = 59 * this.m_globalId % 360 + seed; if (spawnCharacterData.IsFlying()) { LogicCharacterData parentData = this.GetCharacterData(); position.Set(this.GetX() + LogicMath.GetRotatedX(parentData.GetSecondarySpawnOffset(), 0, rnd), this.GetY() + LogicMath.GetRotatedY(parentData.GetSecondarySpawnOffset(), 0, rnd)); } else if (spawnCharacterData.GetSpeed() == 0) { position.Set(this.GetX(), this.GetY()); } else { if (!this.m_level.GetTileMap().GetNearestPassablePosition(this.GetX(), this.GetY(), position, 1536)) { continue; } } LogicCharacter spawnGameObject = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnCharacterData, this.m_level, this.m_villageType); if (this.GetCharacterData().GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop() != null || this.IsHero()) { this.m_summonTroops.Add(spawnGameObject); } spawnGameObject.GetHitpointComponent().SetTeam(team); spawnGameObject.SetUpgradeLevel(upgLevel); spawnGameObject.SetInitialPosition(position.m_x, position.m_y); if (this.m_duplicate) { spawnGameObject.m_duplicateLifeTime = this.m_duplicateLifeTime; spawnGameObject.m_duplicate = true; } if (!this.IsHero()) { spawnGameObject.m_summoner = (LogicCharacterData)this.m_data; } if (invulnerabilityTime > 0) { spawnGameObject.GetHitpointComponent().SetInvulnerabilityTime(invulnerabilityTime); } int secondarySpawnDistance = this.IsHero() ? 768 : this.GetCharacterData().GetSecondarySpawnDistance(); if (secondarySpawnDistance > 0) { if (randomizeSecSpawnDist) { secondarySpawnDistance = (int)(random.Rand(secondarySpawnDistance) + ((uint)secondarySpawnDistance >> 1)); } position.Set(LogicMath.Cos(rnd, secondarySpawnDistance), LogicMath.Sin(rnd, secondarySpawnDistance)); int pushBackSpeed = spawnGameObject.GetCharacterData().GetPushbackSpeed(); if (pushBackSpeed <= 0) { pushBackSpeed = 1; } int pushBackTime = 2 * secondarySpawnDistance / (3 * pushBackSpeed); if (this.GetHitpointComponent().GetHitpoints() > 0) { if (this.GetAttackerItemData().GetSummonTroop() != null) { spawnGameObject.SetSpawnTime(pushBackTime); } else if (this.IsHero()) { spawnGameObject.SetSpawnTime(pushBackTime + k); } } spawnGameObject.GetMovementComponent().GetMovementSystem().PushTrap(position, pushBackTime, 0, false, false); } if (team == 1 || spawnGameObject.GetCharacterData().IsJumper()) { spawnGameObject.GetMovementComponent().EnableJump(3600000); spawnGameObject.GetCombatComponent().RefreshTarget(true); } if (team == 1) { if (LogicDataTables.GetGlobals().AllianceTroopsPatrol()) { spawnGameObject.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9); if (this.GetMovementComponent().GetBaseBuilding() != null) { spawnGameObject.GetMovementComponent().SetBaseBuilding(this.GetMovementComponent().GetBaseBuilding()); } } } this.GetGameObjectManager().AddGameObject(spawnGameObject, -1); if (this.IsHero()) { ++this.m_summonSpawnCount; } } position.Destruct(); } } else { Debugger.Warning("checkSpawning: trying to spawn normal troops!"); } }
public void PushTrap(LogicVector2 position, int time, int id, bool ignorePrevPush, bool verifyPushPosition) { if (this.m_pushTime <= 0 || ignorePrevPush) { if (this.m_parent != null && this.m_parent.GetJump() <= 0 && !this.m_parent.GetParent().IsHero()) { LogicGameObject parent = this.m_parent.GetParent(); if (!parent.IsHero()) { if (id != 0 && !ignorePrevPush) { int idx = -1; for (int k = 0; k < 3; k++) { if (this.m_preventsPushId[k] == id) { return; } if (this.m_preventsPushTime[k] == 0) { idx = k; } } if (idx == -1) { return; } this.m_preventsPushId[idx] = id; this.m_preventsPushTime[idx] = 1500; } this.m_pushTime = time; this.m_pushInitTime = time; this.m_pushBackStartPosition.m_x = this.m_position.m_x; this.m_pushBackStartPosition.m_y = this.m_position.m_y; this.m_pushBackEndPosition.m_x = this.m_position.m_x + position.m_x; this.m_pushBackEndPosition.m_y = this.m_position.m_y + position.m_y; if (verifyPushPosition) { int pushBackEndPositionX = this.m_pushBackEndPosition.m_x; int pushBackEndPositionY = this.m_pushBackEndPosition.m_y; if (LogicMath.Max(LogicMath.Abs(position.m_x), LogicMath.Abs(position.m_y)) != 0) { LogicTileMap tileMap = parent.GetLevel().GetTileMap(); if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8)) { LogicVector2 pos = new LogicVector2(); LogicRandom rnd = new LogicRandom(pushBackEndPositionX + pushBackEndPositionY); tileMap.GetNearestPassablePosition(pushBackEndPositionX + rnd.Rand(512) - 256, pushBackEndPositionY + rnd.Rand(512) - 256, pos, 2048); pushBackEndPositionX = pos.m_x; pushBackEndPositionY = pos.m_y; } if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8)) { Debugger.Warning("PushTrap->ended on inmovable"); } } this.m_pushBackEndPosition.m_x = pushBackEndPositionX; this.m_pushBackEndPosition.m_y = pushBackEndPositionY; } this.m_ignorePush = verifyPushPosition; int angle = position.GetAngle(); this.m_direction = angle + (angle <= 180 ? 180 : -180); } } } }