// LOGIC public void SetSeed(int i_Seed) { TSRandom tsRandom = TSRandom.New(i_Seed); TSRandom.instance = tsRandom; m_Seed = i_Seed; }
/// <summary> /// 重生 /// </summary> public void Respawn() { // 死亡次数加一 _death++; // 重置生命值 _syncedHealth.Reset(); // 设置随机出生位置 tsTransform.position = new TSVector(TSRandom.Range(-5, 5), 0, TSRandom.Range(-5, 5)); }
/** * @brief Generates a new instance based on a given seed. **/ public static TSRandom New(int seed) { TSRandom r = new TSRandom(seed); //StateTracker.AddTracking(r, "mt"); //StateTracker.AddTracking(r, "mti"); return(r); }
public override void OnSyncedStart() { tsTransform.position = new TSVector(TSRandom.Range(-5, 5), 0, TSRandom.Range(-5, 5)); GameObject inputManagerObject = GameObject.FindWithTag("InputManager"); if (inputManagerObject == null) { Debug.LogError("场景中缺失 SyncedInputManager 对象!"); return; } _syncedInputManager = inputManagerObject.GetComponent <SyncedInputManager>(); if (_syncedInputManager == null) { Debug.LogError("场景中缺失 SyncedInputManager 组件!"); } if (owner.id.Equals(localOwner.id)) { _currentShot = playerShot; } else { _currentShot = enemyShot; } _syncedHealth = GetComponent <SyncedHealth>(); // 如果该对象为本地玩家对象,则将其生命值显示到 UI 控件上 if (owner.id.Equals(localOwner.id)) { GameObject uiCameraObject = GameObject.Find("UICamera"); if (uiCameraObject != null) { UIManager uiManager = uiCameraObject.GetComponent <UIManager>(); if (uiManager != null) { uiManager.PlayerHealth = _syncedHealth; } else { Debug.LogError("Can not get the reference of 'HealthText'!"); } } else { Debug.LogError("GameObject 'UICamera' is missing in the current scene!"); } } _audioSource = GetComponent <AudioSource>(); _death = 0; }
/// <summary> /// Generates a random position using min and max distribution radius /// </summary> /// <returns>new random position (TSVector)</returns> /// FIXME: This method will occasionally generate positions which existing powerups may be already occupying private TSVector getRandomPosition() { // Place the powerup in a random location int direction = TSRandom.Range(0, 359); // Generate general position TSVector TSVector position = TSQuaternion.AngleAxis(direction, TSVector.up).Rotate(TSVector.forward); // Apply distance between min and max distribution radius return(position.normalized * TSRandom.Range(minDistributionRadius, maxDistributionRadius)); }
// UTILS private RespawnPoint GetRandomSpawnPoint() { if (m_RespawnPoints == null || m_RespawnPoints.Length == 0) { return(null); } int randomIndex = TSRandom.Range(0, m_RespawnPoints.Length); return(m_RespawnPoints[randomIndex]); }
private static void Shuffle <T>(IList <T> list) { TSRandom tsRandom = TSRandom.New(0); int count = list.Count; while (count > 1) { --count; int index = tsRandom.Next(0, count + 1); T obj = list[index]; list[index] = list[count]; list[count] = obj; } }
private void Awake() { GridMap.SetNodeSize(1, 1); TSRandom.Init(); _pfm = new PathFindingManager(1); //_pm = PathManager.Instance; _gridGraph._mapSizeX = 50; _gridGraph._mapSizeZ = 50; _gridGraph._startPos = TSVector.zero; _gridGraph.SetUpMap(); _map = _gridGraph._map; //GridMapManager.Instance.CreateGridMap(50, 50, TSVector.zero, 0, this.IsTileUnWalkable); PathFindingAgentBehaviour.C_DESIRED_DELTATIME = 18; s_AstarAgent = new SingleObjectPool <PathFindingAgentBehaviour>(10); }
public override void OnSyncedUpdate() { Cooldown -= TrueSyncManager.DeltaTime; if (TrueSyncInput.GetByte((byte)InputKey.SpawnCoin) == 0 || Cooldown > 0.0 || Coin <= 0) { return; } var position = tsTransform.position; position.x = TSRandom.Range(-3.0f, 3.0f); TrueSyncManager.SyncedInstantiate(CoinPrefab, position, TSQuaternion.identity); Cooldown = 0.2; Coin--; }
void RandCreateBalls() { TSRandom.Init(); FP halfx = TableWidth / 2 - 2 * radius - 5; FP halfy = TableHeight / 2 - 2 * radius - 5; for (int i = 0; i < 20; i++) { var ball = new BallObj(i, new TSVector2(TSRandom.Range((int)(-halfx), (int)halfx), TSRandom.Range((int)(-halfy), (int)halfy)), new TSVector2(TSRandom.Range(-1, 1), TSRandom.Range(-1, 1)).normalized, TSRandom.Range(10, 100), radius); //var ball = new BallObj(i, new TSVector2(TSRandom.Range((int)(-halfx), (int)halfx), TSRandom.Range((int)(-halfy), (int)halfy)), radius); balls.Add(ball); if (ball.ID == 0) { mainBall = ball; } } }
/// <summary> /// Do a deterministic Start to the Game. /// </summary> void managerstart() { TSRandom.instance = TSRandom.New(5); unitcon = GameObject.Find("Controllers"); unitcomscript = unitcon.GetComponent <UnitMovementcommandcontroller>(); unitcomscript.StartMain(); foreach (Transform gam in unitcon.transform) { if (gam.GetComponent <AIController>() != null) { aicontrollers.Add(gam.GetComponent <AIController>()); } } foreach (Transform t in Objects.transform) { if (t.name != "Working" && t.name != "Engines") { t.GetComponent <_Ship>().StartMain(); } } }
/// <summary> // initializes deterministic start. /// <summary> public void StartMain(int randominput) { int a = UnitMovementcommandcontroller.findspawnteamreverse(team); unitcontrol = transform.parent.GetComponent <UnitMovementcommandcontroller>(); crosslevelvar = unitcontrol.crosslevelholder; increaserate = getaimoneyamount(crosslevelvar.botdifficulty, unitcontrol.moneyincreaserate).AsInt(); if (unitcontrol.crosslevelholder.campaign == true && unitcontrol.crosslevelholder.campaignlevel.objective == MainMenuCampaignControlScript.eMissionObjective.Survive && unitcontrol.crosslevelholder.campaignlevel.name == "Final Assault") { increaserate = 80; } else if (unitcontrol.crosslevelholder.campaign == true && unitcontrol.crosslevelholder.campaignlevel.objective == MainMenuCampaignControlScript.eMissionObjective.Survive) { increaserate = 70; } World = GameObject.Find("World").transform.Find("Objects").gameObject; state = AIstate.attacking; debugseed = 5 + a + randominput; randominst = TSRandom.New(debugseed); startpos = new TSVector(0, 0, 0); spawnerhold = a; }
public AbstractForceController() : base(ControllerType.AbstractForceController) { this.Enabled = true; this.Strength = 1f; this.Position = new TSVector2(0, 0); this.MaximumSpeed = 100f; this.TimingMode = AbstractForceController.TimingModes.Switched; this.ImpulseTime = 0f; this.ImpulseLength = 1f; this.Triggered = false; this.StrengthCurve = new Curve(); this.Variation = 0f; this.Randomize = TSRandom.New(1234); this.DecayMode = AbstractForceController.DecayModes.None; this.DecayCurve = new Curve(); this.DecayStart = 0f; this.DecayEnd = 0f; this.StrengthCurve.Keys.Add(new CurveKey(0, 5)); this.StrengthCurve.Keys.Add(new CurveKey(0.1f, 5)); this.StrengthCurve.Keys.Add(new CurveKey(0.2f, -4)); this.StrengthCurve.Keys.Add(new CurveKey(1f, 0)); }
public void OnSyncedCollisionEnter(TSCollision other) { if (other.gameObject.tag == "Food") { // grow slow and destroy food currentScale *= growSlow; // move food to a new place (deterministic randoms) TSRigidBody food = other.rigidbody; food.position = new TSVector(TSRandom.Range(-35, 35), 0, TSRandom.Range(-20, 20)); } else if (other.gameObject.tag == "Player") { LockPlayer enemy = other.gameObject.GetComponent <LockPlayer> (); if (ss.Radius > enemy.ss.Radius) { // grow fast and eat other currentScale *= growFast; enemy.tsRigidBody.position = new TSVector(TSRandom.Range(-35, 35), 0, TSRandom.Range(-20, 20)); enemy.currentScale = FP.One; //TrueSyncManager.SyncedDestroy(other); } } }
public void Respawn() { tsTransform.position = new TSVector(TSRandom.Range(-5, 5), 0, TSRandom.Range(-5, 5)); deaths++; }
public override void OnSyncedStart() { tsTransform.position = new TSVector(TSRandom.Range(-5, 5), 0, TSRandom.Range(-5, 5)); }
IEnumerator SpawnUnit() { if (randomSeed == 0) { randomSeed = (int)System.DateTime.Now.Ticks; } UnityEngine.Random.InitState(randomSeed); TSRandom random = TSRandom.instance; while (true && countLimit > 0) { for (int i = 0; i < 10 && countLimit > 0; i++) { TestAgent tagent = GameObject.Instantiate <TestAgent>(agent); PathFindingAgentBehaviour unit = s_AstarAgent.New(); if (unit != null) { tagent._testPathFinding = this; tagent.unit = unit; int camp = countLimit % campCount; //start pos Vector3 vPos = startObj[camp].transform.position + new Vector3(UnityEngine.Random.Range(0, 2.0f), 0, UnityEngine.Random.Range(0, 2.0f)); TSVector pos = TSVector.zero; pos.Set(CustomMath.FloatToFP(vPos.x), CustomMath.FloatToFP(vPos.y), CustomMath.FloatToFP(vPos.z)); TSVector sPos = pos; tagent.gameObject.transform.position = CustomMath.TsVecToVector3(sPos); // Debug.Log(pos); //target pos Vector3 tpos = destObj[camp].transform.position; // new Vector3(48.0f, 0.0f, 46.8f); pos.Set(CustomMath.FloatToFP(tpos.x), CustomMath.FloatToFP(tpos.y), CustomMath.FloatToFP(tpos.z)); //get center int idx = _map.GetGridNodeId(pos); pos = _map.GetWorldPosition(idx); TSVector targetPos = pos; FP attackRange = _atkRanges[countLimit % _atkRanges.Length]; FP range = TSMath.Max(attackRange + GridMap.GetNodeSize() * CustomMath.FPHalf, FP.One * 3 * GridMap.GetNodeSize()); AgentBaseData data = new AgentBaseData(); data.id = countLimit; data.mapId = 0; data.playerId = camp; data.eAgentType = EAgentType.none; //data.id%5== 0? EAgentType.ingoreObstacle: #if !USING_FLOW_FIELD data.defaultTargetPos = TSVector.zero; //astar #else data.defaultTargetPos = targetPos; #endif data.loopCallback = tagent.Loop; data.boidsType = (byte)EBoidsActiveType.all; data.maxSpeed = FP.One * maxSpeed; data.position = sPos; data.collidesWithLayer = 1; data.viewRadius = FP.One * 6 * GridMap.GetNodeSize(); data.neighbourRadius = range; data.random = random; data.colliderRadius = 0.5f; //test data.pfm = _pfm; data.groupId = (byte)(data.eAgentType == EAgentType.ingoreObstacle ? 1 : 0); data.targetFailCallback = tagent.FailFindPathCallback; unit.enabled = false; unit.Init(data); EAgentType agentType = EAgentType.astar; #if USING_FLOW_FIELD agentType = EAgentType.flowFiled; #endif unit.ChangeAgentType(data.eAgentType == EAgentType.ingoreObstacle? data.eAgentType : agentType); unit.agent.TargetPos = targetPos; // unit.OnEnable();//????????? tagent.attackRange = attackRange; // FP.One * UnityEngine.Random.Range(0.8f, 5); tagent._attackRange = attackRange.AsFloat(); // unit.AgentType = EAgentType.flowFiled; #if !USING_FLOW_FIELD unit.ChangeAgentType(EAgentType.astar); //astar #endif if (groupCount > 0) { AgentGroupManager.instance.UpdateGroup(unit, countLimit % groupCount); } tagent.transform.GetChild(0).GetComponent <SpriteRenderer>().color = _campColor[camp]; // unit.agent.StartPos = unit.position; // unit._agent.TargetPos = (TSVector)destination; tagent.gameObject.name = "unit" + countLimit; tagent.transform.SetParent(Units); // unit.agent.TargetPos = targetPos; // unit.agent._activeBoids = (byte)EBoidsActiveType.all; _listAgents.Add(tagent); // PathFindingManager.Instance.AddAgent(this); //_pm.FindFastPath(unit._agent, unit._agent.StartPos, unit._agent.TargetPos);//, unit._agent._vecPath // break; if (unit.group != null && (unit.group.leader as PathFindingAgentBehaviour) == unit && unit.AgentType == EAgentType.astar) { _pm.FindQuickPath(unit.agent, 10, unit.agent.StartPos, unit.agent.TargetPos, unit.map, false); } //if(unit.group!=null) //{ // unit.agent._activeBoids = (byte)EBoidsActiveType.alignment& (byte)EBoidsActiveType.cohesion & (byte)EBoidsActiveType.terrainSeperation //} countLimit--; if (countLimit % 5 == 0) { yield return(_wait); } } } } yield return(null); }
public override void OnSyncedUpdate() { base.OnSyncedUpdate(); if (!m_IsActive || m_HoleIndex < 0) { return; } // Get Simulation info. int currentTick = TrueSyncManager.ticksMain; int rollbackWindow = TrueSyncManager.rollbackWindowMain; // Check current collision TSVector2 myPosition = tsTransform2D.position; for (int targetIndex = 0; targetIndex < m_Targets.Count; ++targetIndex) { tnHoleTarget holeTarget = m_Targets[targetIndex]; if (holeTarget == null) { continue; } TSTransform2D otherTransform = holeTarget.GetComponent <TSTransform2D>(); if (otherTransform == null) { continue; } TSVector2 targetPosition = otherTransform.position; TSVector2 positionDelta = targetPosition - myPosition; FP distance2 = positionDelta.LengthSquared(); if (distance2 < m_Threshold * m_Threshold) { // Notify collision. holeTarget.CollidingWithHole(); // Add object to pending list. if (holeTarget.canEnterHole && !holeTarget.isTeleporting) { Internal_CacheTarget(currentTick, holeTarget); } } } // Check pending objects. for (int index = 0; index < m_Pending.count; ++index) { int tick = m_Pending.GetKey(index); if (currentTick == tick + rollbackWindow) { List <tnHoleTarget> holeTargets = m_Pending.GetValue(tick); if (holeTargets != null) { for (int targetIndex = 0; targetIndex < holeTargets.Count; ++targetIndex) { tnHoleTarget holeTarget = holeTargets[targetIndex]; if (holeTarget == null) { continue; } RespawnPoint respawnPoint = GetRandomSpawnPoint(); if (respawnPoint == null || respawnPoint.transform == null) { continue; } TSTransform2D targetTransform = holeTarget.tsTransform2D; TSRigidBody2D targetRigidbody = holeTarget.GetComponent <TSRigidBody2D>(); // Snap position. if (targetRigidbody != null) { targetRigidbody.MovePosition(tsTransform2D.position); } else { targetTransform.position = tsTransform2D.position; } // Set rigidbody velocity, if (targetRigidbody != null) { targetRigidbody.velocity = TSVector2.zero; } // Eavluate force TSVector2 forceDirection = respawnPoint.forceDirection; forceDirection.Normalize(); if (MathFP.Abs(respawnPoint.errorAngle) > FP.Zero) { int random = TSRandom.Range(0, 101); FP t = ((FP)random) / 100; FP randomError = MathFP.Lerp(-respawnPoint.errorAngle, respawnPoint.errorAngle, t); forceDirection = forceDirection.Rotate(randomError); } TSVector2 outForce = forceDirection * respawnPoint.forceIntensity; // Teleport. holeTarget.Teleport(m_HoleIndex, respawnPoint.respawnPosition, outForce, m_RespawnTime, m_InEffect, m_OutEffect); } } } } // Remove old data from dictionary. for (int index = 0; index < m_Pending.count; ++index) { int tick = m_Pending.GetKey(index); int executionTick = tick + rollbackWindow; bool isSafeTick = TrueSyncManager.IsTickOutOfRollbackMain(executionTick); if (isSafeTick) { m_Pending.Remove(tick); index = -1; } } }
/// <summary> // deterministic start. /// <summary> public void StartMain(int inputint) { started = true; i = inputint; startcount = 0; customran = TSRandom.New(transform.parent.GetComponent <PhotonView>().viewID + inputint); parentscript = transform.parent.GetComponent <_Ship>(); if (guntypemain == guntype.EngineUpgrade) { parentscript.MaxSpeed = parentscript.MaxSpeed * 1.15f; } if (guntypemain == guntype.HPUpgrade) { parentscript.Armor = Mathf.RoundToInt(parentscript.Armor * 1.15f); } if (guntypemain == guntype.WeaponUpgrade) { foreach (Transform gun in transform.parent) { if (gun.tag == "Pickup") { _Weapon gunwep = gun.GetComponent <_Weapon>(); gunwep.timebetweenshots = gunwep.timebetweenshots * 1.15; } } } if (guntypemain == guntype.Cloak) { parentscript.iscloacked = true; } if (guntypemain == guntype.Tracker) { parentscript.isTracker = true; } unittargetcontrol = GameObject.Find("Controllers").GetComponent <UnitMovementcommandcontroller>(); poolmanager = GameObject.Find("F3dPoolManager").GetComponent <F3DPoolManager>(); team = parentscript.ShipColor; if (verticalmovechild == null && transform.childCount > 0 && transform.GetChild(0).childCount > 0) { verticalmovechild = transform.GetChild(0).GetChild(0).gameObject; } _Ship parent = transform.parent.GetComponent <_Ship>(); if (Cannon_Projectile != null) { parent.Cannon_Projectile = Cannon_Projectile; } if (Missile_Projectile != null) { parent.Missile_Projectile = Missile_Projectile; } if (MiniGun_Projectile != null) { parent.MiniGun_Projectile = MiniGun_Projectile; } if (Lazer_Proectile != null) { parent.Lazer_Shot = Lazer_Proectile; } parent.shieldmaterial = shieldmatgam; damage = Calculate_damage(); audiosource = GetComponent <AudioSource>(); WorldBase = GameObject.Find("WorldScaleBase"); timepassed = 0; }
internal static void Init() { instance = New(1); }